package com.itguigu.project.ai.config;

import com.itguigu.project.ai.store.MongoChatMemoryStore;
import dev.langchain4j.memory.chat.ChatMemoryProvider;
import dev.langchain4j.memory.chat.MessageWindowChatMemory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author lxr
 * @date 2025/11/8 16:56
 * 隔离性配置
 */
@Configuration
public class SeparateChatAssistantConfig {
    @Autowired
    MongoChatMemoryStore mongoChatMemoryStore;

    @Bean
    ChatMemoryProvider chatMemoryProvider(){

        //实际返回值为子类类型 ChatMemory ->  子类MessageWindowChatMemory
        return memoryId -> MessageWindowChatMemory.builder()
                .id(memoryId)
                .maxMessages(10) // 可存储次数
                .chatMemoryStore(mongoChatMemoryStore) //配置持久化对象
                .build();

    }
}
